import { Z, ee, te, ne, X, oe, qr, br } from './cell'
export default class Q {
  constructor(t, n) {
    this.changedData = t
    this.hotInstance = n
    this.diffObject = []
  }
  diff() {
    return this.changedData.cellMetas && this.diffObject.push(new Z(this.changedData.cellMetas, this.hotInstance).diff()),
      this.changedData.hasOwnProperty("mergeCells") && this.diffObject.push(new ee(this.changedData.mergeCells, this.hotInstance).diff()),
      this.changedData.cellData && this.diffObject.push(new te(this.changedData.cellData, this.hotInstance).diff()),
      this.changedData.cellFields && this.diffObject.push(new ne(this.changedData.cellFields, this.hotInstance).diff()),
      this.changedData.cellImgs && this.diffObject.push(new X(this.changedData.cellImgs, this.hotInstance).diff()),
      this.changedData.cellWithBRcode && this.diffObject.push(new br(this.changedData.cellWithBRcode, this.hotInstance).diff()),
      this.changedData.cellWithQRcode && this.diffObject.push(new qr(this.changedData.cellWithQRcode, this.hotInstance).diff()),
      this.changedData.tableStructure && this.diffObject.push(new oe(this.changedData.tableStructure, this.hotInstance).diff()),
      this
  }

  applyChange(e) {
    this.diffObject.forEach(function (t) {
      t.applyChange(e)
    })
    "UndoRedo.undo" !== e && "UndoRedo.redo" !== e && "UndoRedo.Undo" !== e && this.hotInstance.runHooks("afterChangeSetDone", this.applyChange.bind(this), this.revertChange.bind(this))
    this.hotInstance.render()
  }

  revertChange() {
    this.diffObject.forEach(function (e) {
      e.revertChange()
    })
    this.hotInstance.render()
  }
}